<template>
  <div class="container">
    <data-view
      propViewKey="dept_oprt_use"
      propViewForm="dept/oprtuse/detail.vue"
      :propFlowKey="propFlowKey"
      :propShowToolBar="true"
      ref="dataview"
      @extra-button-click="extraButtonClick"
      :propIsTdesign="true"
      :propParam="cpPropParam"
    />
  </div>
</template>

<script>

export default {
  name: 'oprtuse',
  data() {
    return {

    }
  },
  computed: {
    cpPropParam() {
      let obFromUrl = this.utils.getObFromUrl(this.propParameter)
      let param = {}
      if ([1,'1'].includes(obFromUrl.input)) {
        param.flagInput = 1
      }
      return param
    }
  },
  methods: {
    extraButtonClick(para) {
      let buttonKey = para.button.key
      if (buttonKey === 'pushDeptOprtUse') {
        this.pushDeptOprtUse(para.data)
      } else if (buttonKey === 'auditDeptOprtUse') {
        this.auditDeptOprtUse(para.data)
      }
    },
    pushDeptOprtUse(data) {
      if (!data || data.length == 0) {
        this.utilMessage.error('请先选中病人消耗单')
        return
      }
      let length = data.filter(row => row.flowStatus == 'end' && !row.flagPushed).length
      if (length != data.length) {
        this.utilMessage.error('只有已审核未推送的病人消耗单才允许推送')
        return
      }
      this.utilVue.loadShow(true)
      let idList = []
      data.forEach(item => {
        const {id} = item
        idList.push(id)
      })
      this.$ajax.post('/dept/oprt_use/pushDeptOprtUse', idList).then(resp => {
        if (resp.code == 0) {
          this.utilMessage.success(resp.msg)
          this.$refs.dataview.ocRefresh()
          this.utilVue.loadHide()
        }
        this.$refs.dataview.ocRefresh()
      })
    },
    // 科室审核
    auditDeptOprtUse(data) {
      if (!data || data.length == 0) {
        this.utilMessage.error('请先选中病人消耗单')
        return
      }
      this.utilVue.loadShow(true)
      let idList = []
      data.forEach(item => {
        const {id} = item
        idList.push(id)
      })
      this.$ajax.post('/dept/oprt_use/auditDeptOprtUse', idList).then(resp => {
        if (resp.code == 0) {
          this.utilMessage.success(resp.msg)
          this.$refs.dataview.ocRefresh()
          this.utilVue.loadHide()
        }
        this.$refs.dataview.ocRefresh()
      })
    },
  },
  props: ['propFlowKey', 'propParameter'],
}
</script>

<style lang="scss" scoped>
  .container {
    height: 100%;
    background-color: #fff;
  }
</style>
